package MainComponent;
import impl.*;

import java.io.File;
import java.util.ArrayList;

import dataobj.CourseTO;

/***
 * Get the course
 */
public class CourseOperate {
	
	private UniversityImpl impl;
	
	/***
	 * Class constructor.
	 */
	public CourseOperate(){
		impl = null;
	}
	
	/***
	 * Class constructor specifying the name of the university.
	 * @param university	the name of the university
	 */
	public CourseOperate(String university){
		try {
			impl = (UniversityImpl) Class.forName("impl."+university+"Impl").newInstance();
		} catch (Exception e) {
			ui.UI.showErrorMessage("Not such university");
			impl = null;
		}
	}
	
	/***
	 * Get the course according to the stored implementation and the file.
	 * @param file	the input file
	 * @return	the array list of the course objects
	 */
	public ArrayList<CourseTO> getCourses(File file) {
		if(impl!=null)
			return impl.getCourses(file);
		else
			return new ArrayList<CourseTO>();
	}

}
